package com.vimi8.ebb.auth.model;

import java.util.*;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;


/**
 * 客户端信息,必需继承org.springframework.security.oauth2.provider.client.BaseClientDetails.
 **/

/**
 * 客户端信息,必需继承org.springframework.security.oauth2.provider.client.BaseClientDetails.
 */
@ApiModel(description = "客户端信息,必需继承org.springframework.security.oauth2.provider.client.BaseClientDetails.")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.SpringCodegen", date = "2016-10-11T03:28:06.909Z")

public class DBClientDetails   extends org.springframework.security.oauth2.provider.client.BaseClientDetails {
  protected Logger logger = LoggerFactory.getLogger(this.getClass());

  private Boolean allowUsersToJoin = null;

  private String autoResources = null;

  private String manuResources = null;

  private String autoScopes = null;

  private String manuScopes = null;
  private String grantTypes=null;
  private String redirectUri=null;
  private Integer accessTokenExpiresIn=0;

  public DBClientDetails allowUsersToJoin(Boolean allowUsersToJoin) {
    this.allowUsersToJoin = allowUsersToJoin;
    return this;
  }

  public void  setAccessTokenExpiresIn(int accessTokenExpiresIn){
    super.setAccessTokenValiditySeconds(accessTokenExpiresIn);
  }

  public void  setRefreshTokenExpiresIn(int refreshTokenExpiresIn){
    super.setRefreshTokenValiditySeconds (refreshTokenExpiresIn);
  }

  /**
   * 允许用户加入.
   * @return allowUsersToJoin
   **/
  @ApiModelProperty(value = "允许用户加入.")
  public Boolean getAllowUsersToJoin() {
    return allowUsersToJoin;
  }

  public void setAllowUsersToJoin(Boolean allowUsersToJoin) {
    this.allowUsersToJoin = allowUsersToJoin;
  }

  public DBClientDetails autoResources(String autoResources) {
    this.autoResources = autoResources;
    return this;
  }

  /**
   * 自动资源.
   * @return autoResources
   **/
  @ApiModelProperty(value = "自动资源.")
  public String getAutoResources() {
    return autoResources;
  }

  public void setAutoResources(String autoResources) {
    this.autoResources = autoResources;
    //logger.warn("setAutoResources:"+autoResources);
    if (!StringUtils.isEmpty(autoResources)) {
      List<String> resourceIds = new ArrayList<>(Arrays.asList(autoResources.split("\\|")));
      //追加之前的
      //logger.warn("----1super.getResourceIds:"+super.getResourceIds());
      if(super.getResourceIds()!=null && super.getResourceIds().size()>0){
        resourceIds.addAll(super.getResourceIds());
      }
      super.setResourceIds(resourceIds);
      //logger.warn("----2super.getResourceIds:"+super.getResourceIds());
    }
  }

  public DBClientDetails manuResources(String manuResources) {
    this.manuResources = manuResources;
    return this;
  }

  /**
   * 手动资源.
   * @return manuResources
   **/
  @ApiModelProperty(value = "手动资源.")
  public String getManuResources() {
    return manuResources;
  }

  public void setManuResources(String manuResources) {
    this.manuResources = manuResources;
    //logger.warn("setManuResources:"+manuResources);
    //不管是手动批准还是自动批准的都属于client的资源
    if (!StringUtils.isEmpty(manuResources)) {
      List<String> resourceIds = new ArrayList<>(Arrays.asList(manuResources.split("\\|")));
      //追加之前的
      //logger.warn("----1super.getResourceIds:"+super.getResourceIds());
      if(super.getResourceIds()!=null&& super.getResourceIds().size()>0){
        resourceIds.addAll(super.getResourceIds());
      }
      super.setResourceIds(resourceIds);
      //logger.warn("----2super.getResourceIds:"+super.getResourceIds());
    }
  }

  public DBClientDetails autoScopes(String autoScopes) {
    this.autoScopes = autoScopes;
    return this;
  }

  /**
   * 自动权限范围.
   * @return autoScopes
   **/
  @ApiModelProperty(value = "自动权限范围.")
  public String getAutoScopes() {
    return autoScopes;
  }

  public void setAutoScopes(String autoScopes) {
    this.autoScopes = autoScopes;
    //logger.warn("setAutoScopes:"+autoScopes);
    if (!StringUtils.isEmpty(autoScopes)) {
      //不管是手动批准还是自动批准的都属于client的权限范围
      //追加之前的
      //logger.warn("----1super.getScope:"+super.getScope());
      LinkedHashSet<String> scopeset = new LinkedHashSet(super.getScope()) ;
      scopeset.addAll(Arrays.asList(autoScopes.split("\\|")));
      super.setScope(scopeset);
      //logger.warn("----2super.getScope:"+super.getScope());
    }
  }

  public DBClientDetails manuScopes(String manuScopes) {
    this.manuScopes = manuScopes;
    return this;
  }

  /**
   * 手动权限范围.
   * @return manuScopes
   **/
  @ApiModelProperty(value = "手动权限范围.")
  public String getManuScopes() {
    return manuScopes;
  }

  public void setManuScopes(String manuScopes) {
    this.manuScopes = manuScopes;
    //logger.warn("setManuScopes:"+manuScopes);
    //不管是手动批准还是自动批准的都属于client的权限范围
    if (!StringUtils.isEmpty(manuScopes)) {
      //追加之前的
      //logger.warn("----1super.getScope:"+super.getScope());
      LinkedHashSet<String> scopeset = new LinkedHashSet(super.getScope()) ;
      scopeset.addAll(Arrays.asList(manuScopes.split("\\|")));
      super.setScope(scopeset);
      //logger.warn("----2super.getScope:"+super.getScope());
    }
  }


  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    DBClientDetails dBClientDetails = (DBClientDetails) o;
    return Objects.equals(this.allowUsersToJoin, dBClientDetails.allowUsersToJoin) &&
            Objects.equals(this.autoResources, dBClientDetails.autoResources) &&
            Objects.equals(this.manuResources, dBClientDetails.manuResources) &&
            Objects.equals(this.autoScopes, dBClientDetails.autoScopes) &&
            Objects.equals(this.manuScopes, dBClientDetails.manuScopes);
  }

  @Override
  public int hashCode() {
    return Objects.hash(allowUsersToJoin, autoResources, manuResources, autoScopes, manuScopes);
  }

  @Override
  public String toString() {
    return "DBClientDetails{" +
            "allowUsersToJoin=" + allowUsersToJoin +
            ", autoResources='" + autoResources + '\'' +
            ", manuResources='" + manuResources + '\'' +
            ", autoScopes='" + autoScopes + '\'' +
            ", manuScopes='" + manuScopes + '\'' +
            ", grantTypes='" + grantTypes + '\'' +
            ", redirectUri='" + redirectUri + '\'' +
            ", accessTokenExpiresIn=" + accessTokenExpiresIn +
            '}';
  }

  /**
   * Convert the given object to string with each line indented by 4 spaces
   * (except the first line).
   */
  private String toIndentedString(Object o) {
    if (o == null) {
      return "null";
    }
    return o.toString().replace("\n", "\n    ");
  }

  public String getGrantTypes() {
    return grantTypes;
  }

  public void setGrantTypes(String grantTypes) {
    this.grantTypes=grantTypes;
    if(!StringUtils.isEmpty(grantTypes)){
      super.setAuthorizedGrantTypes(Arrays.asList(grantTypes.split("\\|")));
    }
  }

//  public static void main(String args[]){
//
//    DBClientDetails dbClientDetails=new DBClientDetails();
//    dbClientDetails.setGrantTypes("password");
//    System.out.print("-----------------:"+dbClientDetails.getGrantTypes());
//
//  }
}

